package com.hutu.comment.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hutu.comment.common.BaseResponse;
import com.hutu.comment.common.ErrorCode;
import com.hutu.comment.common.ResultUtils;
import com.hutu.comment.domain.dto.CommentDto;
import com.hutu.comment.domain.dto.QuestionCollectedDto;
import com.hutu.comment.domain.dto.ResultDto;
import com.hutu.comment.domain.dto.request.CommentQueryRequest;
import com.hutu.comment.domain.dto.request.UserQueryRequest;
import com.hutu.comment.exception.ThrowUtils;
import com.hutu.comment.service.TbCommentService;
import com.hutu.comment.service.TbQuestionService;
import com.hutu.comment.service.TbUserCollectedQuestionService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
@RequiredArgsConstructor
public class CommentController {

    private final TbQuestionService tbQuestionService;

    private final TbUserCollectedQuestionService tbUserCollectedQuestionService;

    private final TbCommentService tbCommentService;

    /**
     * 根据标题来查询封装的结果
     * @param title
     * @return
     */
    @GetMapping("getQuestionInfo/{title}")
    private BaseResponse<ResultDto> getAll(@PathVariable("title") String title){
        ResultDto resultDto = tbQuestionService.findContentByTitle(title);
        return ResultUtils.success(resultDto);
    }

    /**
     * 是收藏还是取消收藏
     * @param questionCollectedDto
     * @return
     */
    @PostMapping("question/collected")
    private BaseResponse<Boolean> collected(@RequestBody QuestionCollectedDto questionCollectedDto){
        return ResultUtils.success(tbUserCollectedQuestionService.saveOrDeleteCollectedQuestion(questionCollectedDto));
    }



    @PostMapping("/list/page")
    public BaseResponse<Page<CommentDto>> commentPage(@RequestBody CommentQueryRequest commentQueryRequest) {
        return ResultUtils.success(tbCommentService.commentPage(commentQueryRequest));
    }





}
